from PyQt4 import QtGui, QtCore; #@UnusedImport

class Settings_General(QtCore.QObject):    
    def __init__(self, parent):
        super(Settings_General, self).__init__();
        self.parent = parent;
        self.mainWin = parent.mainWin;
        self.graphScene = parent.graphScene;
#        self.actionCmds = parent.actionCmds;
        self.createSettings_General();
        
    def onBtnHidActsClick(self):
        self.hideActions(not self.btnHidActs.isChecked());
    
    def onBtnHidEdgeClick(self):
        self.hideEdges(not self.btnHidEdge.isChecked());
    
    def onBtnFrntActsClick(self):
        self.setActionsFront(not self.btnFrntActs.isChecked());
    
    def onBtnFrntEdgeClick(self):
        self.setEdgesFront(not self.btnFrntEdge.isChecked());
    
    def onBtnMoveOnClick(self):
        self.setMovable(True);
    
    def onBtnMoveOffClick(self):
        self.setMovable(False);
    
    def onBtnSelectOnClick(self):
        self.setSelectable(True);
    
    def onBtnSelectOffClick(self):
        self.setSelectable(False);
        
#    def onCbxStBkgClrClick(self, iVal):
#        if iVal < 3:
#            self.graphScene.graphView.setNodes_BkgColorType(iVal);
#            self.lblStBkgClrDim.setVisible(False);
#            self.cbxStBkgClrDim.setVisible(False);
#        else:
#            self.graphScene.graphView.setNodes_BkgColorType(3, 0, 10);
#            self.cbxStBkgClrDim.setCurrentIndex(0);
#            self.lblStBkgClrDim.setVisible(True);
#            self.cbxStBkgClrDim.setVisible(True);
        
#    def onCbxStBkgClrDimClick(self, iVal):
#        self.graphScene.graphView.setNodes_BkgColorType(3, iVal, 10);
#        
#    def onCbxActBkgClrClick(self, iVal):
#        self.graphScene.graphView.setActions_BkgColorType(iVal);
        
    def onCbxThemeClick(self, iVal):
        self.graphScene.graphView.setNodes_Theme(iVal);
            
    def updateSelectedSettings(self):
        self.onBtnHidActsClick();
        self.onBtnHidEdgeClick();
        self.onBtnFrntActsClick();
        self.onBtnFrntEdgeClick();
        if self.btnMoveOn.isChecked():
            self.onBtnMoveOnClick();
        if self.btnMoveOff.isChecked():
            self.onBtnMoveOffClick();
        #Issue: When Turning Off Nodes Selectable, they are not removed when rebuilding the graph
#        if self.btnSelectOn.isChecked():
#            self.onBtnSelectOnClick();
#        elif self.btnSelectOff.isChecked():
#            self.onBtnSelectOffClick();
        self.onCbxThemeClick(self.cbxTheme.currentIndex());
        
    def createSettings_General(self):
        self.chkHidAct = QtGui.QCheckBox("Hide Actions", self.mainWin);
        self.chkHidEdge = QtGui.QCheckBox("Hide Edges", self.mainWin);
        self.chkActFront = QtGui.QCheckBox("Send Actions Front", self.mainWin);
        self.chkEdgeFront = QtGui.QCheckBox("Send Edges Front", self.mainWin);
        
        self.lblHide = QtGui.QLabel("Hide:", self.mainWin);
        self.btnHidActs = QtGui.QPushButton("Actions", self.mainWin);
        self.btnHidEdge = QtGui.QPushButton("Edges", self.mainWin);
        self.btnHidActs.setCheckable(True);
        self.btnHidEdge.setCheckable(True);
        self.btnHidActs.setMaximumWidth(45);
        self.btnHidEdge.setMaximumWidth(45);
        self.btnHidActs.connect(self.btnHidActs, QtCore.SIGNAL("clicked()"), self.onBtnHidActsClick);
        self.btnHidEdge.connect(self.btnHidEdge, QtCore.SIGNAL("clicked()"), self.onBtnHidEdgeClick);
        self.hBox = QtGui.QHBoxLayout();
        self.hBox.addWidget(self.btnHidActs);
        self.hBox.addWidget(self.btnHidEdge);
        self.hBox.setMargin(0);
        self.qWidgetHide = QtGui.QWidget(self.mainWin);
        self.qWidgetHide.setLayout(self.hBox);
        
        self.lblSendFrnt = QtGui.QLabel("Send Front:", self.mainWin);
        self.btnFrntActs = QtGui.QPushButton("Actions", self.mainWin);
        self.btnFrntEdge = QtGui.QPushButton("Edges", self.mainWin);
        self.btnFrntActs.setCheckable(True);
        self.btnFrntEdge.setCheckable(True);
        self.btnFrntActs.setMaximumWidth(45);
        self.btnFrntEdge.setMaximumWidth(45);
        self.btnFrntActs.connect(self.btnFrntActs, QtCore.SIGNAL("clicked()"), self.onBtnFrntActsClick);
        self.btnFrntEdge.connect(self.btnFrntEdge, QtCore.SIGNAL("clicked()"), self.onBtnFrntEdgeClick);
        self.hBox = QtGui.QHBoxLayout();
        self.hBox.addWidget(self.btnFrntActs);
        self.hBox.addWidget(self.btnFrntEdge);
        self.hBox.setMargin(0);
        self.qWidgetSendFrnt = QtGui.QWidget(self.mainWin);
        self.qWidgetSendFrnt.setLayout(self.hBox);
        
        self.lblMove = QtGui.QLabel("Movable:", self.mainWin);
        self.btnMoveOn = QtGui.QPushButton("Set On", self.mainWin);
        self.btnMoveOff = QtGui.QPushButton("Set Off", self.mainWin);
        self.btnMoveOn.setAutoExclusive(True);
        self.btnMoveOff.setAutoExclusive(True);
        self.btnMoveOn.setCheckable(True);
        self.btnMoveOff.setCheckable(True);
        self.btnMoveOn.setChecked(True);
        self.btnMoveOn.setMaximumWidth(45);
        self.btnMoveOff.setMaximumWidth(45);
        self.btnMoveOn.connect(self.btnMoveOn, QtCore.SIGNAL("clicked()"), self.onBtnMoveOnClick);
        self.btnMoveOff.connect(self.btnMoveOff, QtCore.SIGNAL("clicked()"), self.onBtnMoveOffClick);
        self.hBoxMove = QtGui.QHBoxLayout();
        self.hBoxMove.addWidget(self.btnMoveOn);
        self.hBoxMove.addWidget(self.btnMoveOff);
        self.hBoxMove.setMargin(0);
        self.qWidgetMove = QtGui.QWidget(self.mainWin);
        self.qWidgetMove.setLayout(self.hBoxMove);
        
        self.lblSelect = QtGui.QLabel("Selectable:", self.mainWin);
        self.btnSelectOn = QtGui.QPushButton("Set On", self.mainWin);
        self.btnSelectOff = QtGui.QPushButton("Set Off", self.mainWin);
        self.btnSelectOn.setAutoExclusive(True);
        self.btnSelectOff.setAutoExclusive(True);
        self.btnSelectOn.setCheckable(True);
        self.btnSelectOff.setCheckable(True);
        self.btnSelectOn.setChecked(True);
        self.btnSelectOn.setMaximumWidth(45);
        self.btnSelectOff.setMaximumWidth(45);
        self.btnSelectOn.connect(self.btnSelectOn, QtCore.SIGNAL("clicked()"), self.onBtnSelectOnClick);
        self.btnSelectOff.connect(self.btnSelectOff, QtCore.SIGNAL("clicked()"), self.onBtnSelectOffClick);
        self.hBoxSelect = QtGui.QHBoxLayout();
        self.hBoxSelect.addWidget(self.btnSelectOn);
        self.hBoxSelect.addWidget(self.btnSelectOff);
        self.hBoxSelect.setMargin(0);
        self.qWidgetSelect = QtGui.QWidget(self.mainWin);
        self.qWidgetSelect.setLayout(self.hBoxSelect);
        
        self.lblTheme = QtGui.QLabel("Theme:", self.mainWin);
        self.cbxTheme = QtGui.QComboBox(self.mainWin);
        self.cbxTheme.addItems(["Generic", "Maze"]);
        self.cbxTheme.connect(self.cbxTheme, 
                               QtCore.SIGNAL("currentIndexChanged(int)"), 
                               self.onCbxThemeClick);
        self.cbxTheme.setMaximumWidth(100);
        self.cbxTheme.setMinimumWidth(100);
        self.cbxTheme.setCurrentIndex(1);
        
#        self.lblStBkgClr = QtGui.QLabel("State Bkg Color:", self.mainWin);
#        self.cbxStBkgClr = QtGui.QComboBox(self.mainWin);
#        self.cbxStBkgClr.addItems(["None", "By Value", "By Reward", "By Dimension"]);
#        self.cbxStBkgClr.connect(self.cbxStBkgClr, 
#                              QtCore.SIGNAL("currentIndexChanged(int)"), 
#                              self.onCbxStBkgClrClick);
#        self.cbxStBkgClr.setMaximumWidth(100);
#        self.cbxStBkgClr.setMinimumWidth(100);
#        
#        self.lblStBkgClrDim = QtGui.QLabel("Dimension:", self.mainWin);
#        self.lblStBkgClrDim.setVisible(False);
#        self.cbxStBkgClrDim = QtGui.QComboBox(self.mainWin);
#        self.cbxStBkgClrDim.addItems(self.parent.dataContainer.dataModel.stDimNames);
#        self.cbxStBkgClrDim.connect(self.cbxStBkgClrDim, 
#                              QtCore.SIGNAL("currentIndexChanged(int)"), 
#                              self.onCbxStBkgClrDimClick);
#        self.cbxStBkgClrDim.setMaximumWidth(100);
#        self.cbxStBkgClrDim.setMinimumWidth(100);
#        self.cbxStBkgClrDim.setVisible(False);
#        
#        self.lblActBkgClr = QtGui.QLabel("Action Bkg Color:", self.mainWin);
#        self.cbxActBkgClr = QtGui.QComboBox(self.mainWin);
#        self.cbxActBkgClr.addItems(["None", "By Q-Value"]);
#        self.cbxActBkgClr.connect(self.cbxActBkgClr, 
#                               QtCore.SIGNAL("currentIndexChanged(int)"), 
#                               self.onCbxActBkgClrClick);
#        self.cbxActBkgClr.setMaximumWidth(100);
#        self.cbxActBkgClr.setMinimumWidth(100);
        
        
        self.gridLayout = QtGui.QGridLayout();
        self.gridLayout.addWidget(self.lblHide,0,0, QtCore.Qt.AlignRight);        
        self.gridLayout.addWidget(self.qWidgetHide,0,1, QtCore.Qt.AlignLeft);
        self.gridLayout.addWidget(self.lblSendFrnt,1,0, QtCore.Qt.AlignRight);        
        self.gridLayout.addWidget(self.qWidgetSendFrnt,1,1, QtCore.Qt.AlignLeft); 
        self.gridLayout.addWidget(self.lblMove,2,0, QtCore.Qt.AlignRight);
        self.gridLayout.addWidget(self.qWidgetMove,2,1, QtCore.Qt.AlignLeft);
        self.gridLayout.addWidget(self.lblSelect,3,0, QtCore.Qt.AlignRight);
        self.gridLayout.addWidget(self.qWidgetSelect,3,1, QtCore.Qt.AlignLeft);
        self.gridLayout.addWidget(self.lblTheme,4,0, QtCore.Qt.AlignRight);
        self.gridLayout.addWidget(self.cbxTheme,4,1, QtCore.Qt.AlignLeft);
#        self.gridLayout.addWidget(self.lblStBkgClr,5,0, QtCore.Qt.AlignRight);
#        self.gridLayout.addWidget(self.cbxStBkgClr,5,1, QtCore.Qt.AlignLeft);
#        self.gridLayout.addWidget(self.lblStBkgClrDim,6,0, QtCore.Qt.AlignRight);
#        self.gridLayout.addWidget(self.cbxStBkgClrDim,6,1, QtCore.Qt.AlignLeft);
#        self.gridLayout.addWidget(self.lblActBkgClr,7,0, QtCore.Qt.AlignRight);
#        self.gridLayout.addWidget(self.cbxActBkgClr,7,1, QtCore.Qt.AlignLeft);
        
        self.qWidget = QtGui.QWidget(self.mainWin);
        self.qWidget.setLayout(self.gridLayout);
        self.vBoxMain = QtGui.QVBoxLayout();
        self.vBoxMain.addWidget(self.qWidget); 
        
    #Graph - Settings
    def setMovable(self, bMove):
        self.graphScene.graphView.setNodesMovable(bMove);
    def setSelectable(self, bSelect):
        self.graphScene.graphView.setNodesSelectable(bSelect);
    def hideActions(self, bHideActs):
        self.graphScene.hideActions(bHideActs);
    def hideEdges(self, bHideEdges):
        self.graphScene.graphView.setEdgesVisible(bHideEdges);
    def setActionsFront(self, bActsFrnt):
        self.graphScene.graphView.setActionsBack(bActsFrnt);
    def setEdgesFront(self, bEdgesFrnt):
        if bEdgesFrnt:
            self.graphScene.graphView.setEdgesZVal(-0.2);
        else:
            self.graphScene.graphView.setEdgesZVal(0.2);
            
    #Graph - Background Color
#    def setStBkgColor_None(self):
#        self.graphScene.graphView.setNodes_BkgColorType(0);
#    def setStBkgColor_ByVal(self):
#        self.graphScene.graphView.setNodes_BkgColorType(1);
#    def setStBkgColor_ByR(self):
#        self.graphScene.graphView.setNodes_BkgColorType(2);
#    def setStBkgColor_ByDim(self):
#        self.graphScene.graphView.setNodes_BkgColorType(3, 0,10);
#    def setActBkgColor_None(self):
#        self.graphScene.graphView.setActions_BkgColorType(0);
#    def setActBkgColor_ByQ(self):
#        self.graphScene.graphView.setActions_BkgColorType(1);

        
    def getDataSettings(self):
        aDataSettings = [];
        aDataSettings.append(self.chkHidAct.isChecked());
        aDataSettings.append(self.chkHidEdge.isChecked());
        aDataSettings.append(self.chkActFront.isChecked());
        aDataSettings.append(self.chkEdgeFront.isChecked());
        aDataSettings.append(self.btnHidActs.isChecked());
        aDataSettings.append(self.btnHidEdge.isChecked());
        aDataSettings.append(self.btnFrntActs.isChecked());
        aDataSettings.append(self.btnFrntEdge.isChecked());
        aDataSettings.append(self.btnMoveOn.isChecked());
        aDataSettings.append(self.btnMoveOff.isChecked());
        aDataSettings.append(self.btnSelectOn.isChecked());
        aDataSettings.append(self.btnSelectOff.isChecked());
        aDataSettings.append(self.cbxTheme.currentIndex());
#        aDataSettings.append(self.cbxStBkgClr.currentIndex());
#        aDataSettings.append(self.cbxStBkgClrDim.currentIndex());
#        aDataSettings.append(self.cbxActBkgClr.currentIndex());
        return aDataSettings;
    
    def setDataSettings(self, aDataSettings):
        self.chkHidAct.setChecked(aDataSettings[0]);
        self.chkHidEdge.setChecked(aDataSettings[1]);
        self.chkActFront.setChecked(aDataSettings[2]);
        self.chkEdgeFront.setChecked(aDataSettings[3]);
        self.btnHidActs.setChecked(aDataSettings[4]);
        self.btnHidEdge.setChecked(aDataSettings[5]);        
        self.btnFrntActs.setChecked(aDataSettings[6]);
        self.btnFrntEdge.setChecked(aDataSettings[7]);
        self.btnMoveOn.setChecked(aDataSettings[8]);
        self.btnMoveOff.setChecked(aDataSettings[9]);
        self.btnSelectOn.setChecked(aDataSettings[10]);
        self.btnSelectOff.setChecked(aDataSettings[11]);        
        self.cbxTheme.setCurrentIndex(aDataSettings[12]);
#        self.cbxStBkgClr.setCurrentIndex(aDataSettings[13]);
#        self.cbxStBkgClrDim.setCurrentIndex(aDataSettings[14]);
#        self.cbxActBkgClr.setCurrentIndex(aDataSettings[15]);
        self.updateSelectedSettings();
